local MyView = require "Q2DViewer"
local qt = require "luaQt"

MyView.create2DView = MyView.new_viewer
MyView.NewViewer = MyView.new_viewer

---------------------------------------------------------------------------------------------
--图像设置
function MyView.QCPGraph:setProperty( set )
	 if set.name then self:setName(  qt.NewQString( set.name )  ) end;
	 
	local pen = self:pen();
	pen.width = set.linewidth or pen.width;
	if set.color then
		pen.color = qt.NewQColor( set.color[1] or 1, set.color[2] or 0, set.color[3] or 0 );
	end;
	self:setPen(pen);
end


function MyView.QCPAxis:setAxisWidth( set )
	local basePen = self:basePen();
	local tickPen = self:tickPen();
	local subTickPen = self:subTickPen();
	basePen.width =  set.linewidth or basePen.width;
	tickPen.width = set.linewidth or tickPen.width;
	subTickPen.width = set.linewidth or subTickPen.width;
	
	local selBasePen = self:selectedBasePen();
	local selTickPen = self:selectedTickPen();
	local selSubTickPen = self:selectedSubTickPen();
	selBasePen.width = set.linewidth or selBasePen.width ;
	selTickPen.width = set.linewidth or selTickPen.width ;
	selBasePen.width = set.linewidth or selBasePen.width ;
	
	self:setBasePen(basePen);
	self:setTickPen(tickPen);
	self:setSubTickPen(tickPen);
	self:setSelectedBasePen(selBasePen);
	self:setSelectedTickPen(selTickPen);
	self:setSelectedSubTickPen(selTickPen);
end

function MyView.QCPAxis:setAxisLableFont( set )
	local font = self:labelFont()
	font.pointSize = set.fontsize or font.pointSize;
	self:setLabelFont(font);	
		
	font = self:selectedLabelFont()
	font.pointSize = set.fontsize or font.pointSize;
	self:setSelectedLabelFont(font);
end

function MyView.QCPAxis:setLableColor( set )	
	if set.labelcolor~=nil then
		local c = qt.NewQColor( set.labelcolor[1] or 1, set.labelcolor[2] or 0, set.labelcolor[3] or 0 );
		self:setLabelColor(c)
	end;
end

function MyView.QCPAxis:setTickFont( set )
	local font = self:tickLabelFont()
	font.pointSize = set.fontsize or font.pointSize;
	self:setTickLabelFont(font);
	
		
	font = self:selectedTickLabelFont()
	font.pointSize = set.fontsize or font.pointSize;
	self:setSelectedTickLabelFont(font);
end

function MyView.QCPAxis:setProperty( set )
	 if set.linewidth ~= nil then self:setAxisWidth(set) end
	 if set.fontsize ~= nil then self:setAxisLableFont(set) end
	 if set.tickfontsize ~= nil then self:setTickFont(set) end
	 self:setLableColor(set);
	-- if set.lablecolor ~= nil then self.axis:setLabelColor( c ) end
	if set.name ~= nil then self:setLabel( qt.NewQString( set.name ) ) end
	 if set.subgridvisiable ~= nil then 
		 self:grid():setSubGridVisible( set.subgridvisiable ) 
	 end
	 if set.gridvisiable ~= nil then 
		 self:grid():setVisible( set.gridvisiable ) 
	 end
	  if set.range ~= nil then 
		 self:setRange(  set.range ) 
	 end
	 if set.tickcount ~= nil then
		 (self:ticker()):setTickCount( set.tickcount )
	 end
	 
end
---------------------------------------------------------------------------------------------


function MyView.QCPLegend:setLegendFont( set )
	local font = self:font()
	font.pointSize = set.fontsize or font.pointSize;
	self:setFont(font);	
		
	font = self:selectedFont()
	font.pointSize = set.fontsize or font.pointSize;
	self:setSelectedFont(font);
	
	self:setLegendSize()
end

function MyView.QCPLegend:setProperty( set )
	 if set.fontsize ~= nil then self:setLegendFont(set) end 
end

return MyView;